package com.itheima.service;

import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.dao.AddressDao;
import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.pojo.Address;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;



@Service(interfaceClass =AddressService.class )
@Transactional
public class AddressServiceImpl implements AddressService {
    @Autowired
    AddressDao addressDao;


    @Override
    public void add(Address address) {
      addressDao.add(address);
    }

    @Override
    public void delete(int id) {
        addressDao.delete(id);
    }

    @Override
    public PageResult findPage(QueryPageBean pageBean) {
        Integer currentPage = pageBean.getCurrentPage();
        Integer pageSize = pageBean.getPageSize();
        String queryString = pageBean.getQueryString();
        PageHelper.startPage(currentPage,pageSize);
        Page<Address> page = addressDao.findPage(queryString);
        return new PageResult(page.getTotal(),page.getResult());
    }

    @Override
    public List<Address> findAllAddresses() {
        return addressDao.findAllAddresses();
    }


}

